import React from "react";
import Child from "../Child/Child";

interface ParentState {
  message: string;
  title: string;
}

type ParentProps = Record<string, any>

export default class Parent extends React.Component <ParentProps, ParentState > {
  constructor(props: ParentProps) {
    super(props)
    this.state = {
      message: "我是父组件，需要传入的数据",
      title: ''
    }
  }

  handleData = (childData: string) => {
    console.log(childData)
    this.setState({ title: childData })
  }

  render(): React.ReactNode {
    return (
      <div>
        我是父组件
        <Child message={this.state.message} onData={this.handleData}></Child>
        <h3>{ this.state.title }</h3>
      </div>
    )
  }
}
